<?php 
	session_start();
	include("../service/userService.php");
    include("../util/constant.php");
	$email = $_POST["email"];
	$password = md5($_POST["password"]);
    $user = ConnectionManager::getInstance()->fetch(findUsernameBy($email));
	
    if($user["USER_STATUS"] == 0) echo "<script>window.location.href='../register.php?a=".USER_BANNED."';</script>";
    
	if (authenticateClient($email, $password, 0) == true) {
		$_SESSION['username'][0] = $user["USER_ID"];
		$_SESSION['username'][1] = $user["USER_USERNAME"];
		$_SESSION['username'][2] = 0; // user type
        $_SESSION['userid'] = $user["USER_ID"];
		echo "<script>window.location.href='../index.php';</script>";
	} else echo "<script>window.location.href='../register.php?a=".LOGIN_FAILED."';</script>";
?>
